from typing import Optional, List
from datetime import datetime
from pydantic import ConfigDict
from .base import BaseSchema

class CustomerProfileBase(BaseSchema):
    work_area_id: int
    Name: str
    EnglishName: Optional[str] = None
    Gender: Optional[str] = None
    Birthday: Optional[datetime] = None
    CertificateType: Optional[str] = None
    CertificateNo: Optional[str] = None
    Nationality: Optional[str] = None
    ContactTelNo: Optional[str] = None
    Email: Optional[str] = None
    Remark: Optional[str] = None
    LegacyCustomerNo: Optional[str] = None
    DisplayName: Optional[str] = None
    CompanyName: Optional[str] = None
    CustomerLevel: Optional[str] = None

class CustomerProfileCreate(CustomerProfileBase):
    Gender: str
    Birthday: datetime
    CertificateType: str
    CertificateNo: str
    Nationality: str
    ContactTelNo: str

class CustomerProfileUpdate(CustomerProfileBase):
    Name: Optional[str] = None
    work_area_id: Optional[int] = None

class CustomerProfile(CustomerProfileBase):
    ID: int
    CreateTime: Optional[datetime] = None
    UpdateTime: Optional[datetime] = None

    model_config = ConfigDict(
        from_attributes=True,
        populate_by_name=True
    )

class CustomerProfileList(BaseSchema):
    items: List[CustomerProfile]
    total: int

# 客户联系方式相关的 schema
class CustomerTelNoBase(BaseSchema):
    customer_profile_id: int
    TelNo: str
    Owner: str
    Email: str

class CustomerTelNoCreate(CustomerTelNoBase):
    pass

class CustomerTelNoUpdate(CustomerTelNoBase):
    TelNo: Optional[str] = None
    Owner: Optional[str] = None
    Email: Optional[str] = None

class CustomerTelNo(CustomerTelNoBase):
    ID: int

    model_config = ConfigDict(
        from_attributes=True,
        populate_by_name=True
    )

# 客户地址相关的 schema
class CustomerAddressBase(BaseSchema):
    customer_profile_id: int
    Address: str
    ContactName: str
    ContactTelNo: str

class CustomerAddressCreate(CustomerAddressBase):
    pass

class CustomerAddressUpdate(CustomerAddressBase):
    Address: Optional[str] = None
    ContactName: Optional[str] = None
    ContactTelNo: Optional[str] = None

class CustomerAddress(CustomerAddressBase):
    ID: int

    model_config = ConfigDict(
        from_attributes=True,
        populate_by_name=True
    )

class CustomerPassengerBase(BaseSchema):
    customer_profile_id: int
    Name: str
    EnglishName: Optional[str] = None
    Gender: str
    Birthday: datetime
    CertificateType: str
    CertificateNo: str
    Nationality: str
    Remark: Optional[str] = None

class CustomerPassengerCreate(CustomerPassengerBase):
    pass

class CustomerPassengerUpdate(CustomerPassengerBase):
    pass

class CustomerPassenger(CustomerPassengerBase):
    ID: int
    CreateTime: datetime
    UpdateTime: Optional[datetime] = None

# 其他客户相关的 schema... 